from sqlalchemy.exc import PendingRollbackError
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy import create_engine, Column, Integer, String, Float, text

# 定义基类
from inits import dbSession

Base = declarative_base()

class sk_account_info(Base):
    __tablename__ = 'sk_account_info'  # 数据库中表的名字
    id = Column(Integer, primary_key=True)
    shop_account = Column(String(1000))
    user_id = Column(String(255))
    status = Column(String(1))
    shop_id = Column(Integer)
    dept_id = Column(Integer)
    leader_user_id = Column(Integer)
    user_name = Column(String(500))
    leader_user_ids = Column(String(1000))
    params = Column(String(100))

    def list_shop_account(self, shop_id):
        try:
            res = dbSession.query(sk_account_info).filter(sk_account_info.shop_id.in_(shop_id)).all()
        except PendingRollbackError:
            dbSession.rollback()
        finally:
            dbSession.close()
        return res